<?php
namespace Home\Model;
use Think\Model;

class AuthRuleModel extends Model{

    public $_validate = array(
        array('title','require','请填写菜单名称!'),
        array('name','require','请填写菜单地址!'), 
    );

	protected $_auto = array(
		array('addtime','time',1,'function'),
	);


	public function createTree(){

		$tree = new \Org\Util\Tree();
		$tree->icon = array('│ ', '├─ ', '└─ ');
        $tree->nbsp = '　';
        $result = $this->select();
       	$array = array();
        foreach ($result as $r) {
        	$r['icon'] = $r['status'] == 0?'icon-remove':'icon-ok';
        	$r['info'] = '<div class="fr"><a href="#" onclick="showWindow(\'编辑菜单\',\''.U('AuthRule/edit',array('id'=>$r['id'])).'\',500,400);" class="btn btn-primary btn-mini">编辑</a>';
            if($r['id'] != 1){
                $r['info'] .= ' <a href="#" onclick="showConfirm(\''.U('AuthRule/foreverdelete',array('id'=>$r['id'])).'\');" class="btn btn-danger btn-mini">删除</a></div>';
            }
           	$array[] = $r;
        }

        $tree->init($array);
        $str = "<tr><td>\$id</td><td class='left'>\$spacer\$title</td><td>\$name</td><td><i class='\$icon'></i></td><td>\$info</td></tr>";

        $list = $tree->get_tree(0, $str);
        return $list;
	}

    public function createTreeSelect($pid){

        $tree = new \Org\Util\Tree();
        $tree->icon = array('│ ', '├─ ', '└─ ');
        $tree->nbsp = '　';
        $result = $this->select();
        $array = array();
        foreach ($result as $r) {
            $r['sel'] = $r['id'] == $pid?'selected="selected"':'';
            $array[] = $r;
        }
        $tree->init($array);
        $str = "<option \$sel value='\$id'>\$spacer\$title</option>";
        $list = $tree->get_tree(0, $str);
        return $list;
    }



	
}

?>